package file_info

import (
	"errors"
	"syscall"
)

type fileStat struct {
	*syscall.Stat_t
}

func (s *fileStat) size() int64 {
	return s.Size
}

func (s *fileStat) devNum() uint64 {
	return s.Dev
}

func stat(filename string) (*fileStat, error) {
	var fs syscall.Stat_t
	err := syscall.Stat(filename, &fs)
	if err != nil && !errors.Is(err, syscall.EINTR) {
		return nil, err
	}
	return &fileStat{&fs}, nil
}

func sameFile(fs1, fs2 *fileStat) bool {
	return sameFilesystem(fs1, fs2) && fs1.Ino == fs2.Ino
}

func sameFilesystem(fs1, fs2 *fileStat) bool {
	return fs1.Dev == fs2.Dev
}
